package com.yphone.ui.login.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;


import com.yphone.tools.Constants;
import com.yphone.ui.dialog.CommSmallLoadingDialog;
import com.yphone.ui.login.contract.ForgetPasswrodActivityContract;
import com.yphone.ui.login.presenter.ForgetPasswordActivityPresenter;
import com.yphone.ui.login.view.PwdView;
import com.yphone.ui.login.view.TelView;
import com.yphone.ui.login.view.VerifiView;
import com.yphone.utils.NetworkUtils;
import com.yphone.utils.RegexUtils;
import com.yphone.utils.ToastUtils;
import com.zzkj.yunphone.R;

public class ForgetPasswordActivity extends AppCompatActivity implements ForgetPasswrodActivityContract.IView, View.OnClickListener {
    private PwdView mEdtNewPassword;
    private TelView mEdtPhoneNumber;
    private ForgetPasswrodActivityContract.IPresenter mIPresenter;
    private ImageView mImgBack;
    private ImageView mImgPhoneNumberClean;
    private TextView mTxtFinishAmend;
    private TextView mTxtPhoneFormatRemind;
    private VerifiView mVerifiView;

    public static void toForgetPasswordActivity(Context context) {
        context.startActivity(new Intent(context, ForgetPasswordActivity.class));
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView((int) R.layout.activity_forget_password);
        initDataBeforView();
        initView();
        initData();
        initListener();
    }

    public void initDataBeforView() {
    }

    public void initView() {
        this.mImgBack = (ImageView) findViewById(R.id.activity_forget_password_img_back);
        this.mTxtPhoneFormatRemind = (TextView) findViewById(R.id.activity_forget_password_txt_phone_format_reming);
        this.mTxtPhoneFormatRemind.setVisibility(View.GONE);
        this.mEdtPhoneNumber = (TelView) findViewById(R.id.activity_forget_password_edt_phone_number);
        this.mImgPhoneNumberClean = (ImageView) findViewById(R.id.activity_forget_password_img_phone_number_clean);
        this.mVerifiView = (VerifiView) findViewById(R.id.activity_forget_password_verifi_view);
        this.mVerifiView.setInfo(this, 2);
        this.mEdtNewPassword = (PwdView) findViewById(R.id.activity_forget_password_edt_new_password);
        this.mTxtFinishAmend = (TextView) findViewById(R.id.activity_forget_password_txt_finish_amend);
    }

    public void initListener() {
        this.mImgBack.setOnClickListener(this);
        this.mImgPhoneNumberClean.setOnClickListener(this);
        this.mTxtFinishAmend.setOnClickListener(this);
    }

    public void initData() {
        this.mIPresenter = new ForgetPasswordActivityPresenter(this);
    }

    public void submit() {
        String phone_number = this.mEdtPhoneNumber.getText().toString();
        if (TextUtils.isEmpty(phone_number)) {
            ToastUtils.showLong((CharSequence) getResources().getString(R.string.login_phone_empty));
        } else if (phone_number.length() != 11) {
            ToastUtils.showLong((CharSequence) getString(R.string.phone_format));
        } else {
            String verificationCode = this.mVerifiView.getVerifiCode();
            if (TextUtils.isEmpty(verificationCode)) {
                ToastUtils.showLong((CharSequence) getResources().getString(R.string.verifi_code_empty));
            } else if (verificationCode.length() < 4) {
                ToastUtils.showLong((CharSequence) getResources().getString(R.string.login_verifi_code_four));
            } else {
                String password = this.mEdtNewPassword.getText().toString();
                if (TextUtils.isEmpty(password)) {
                    ToastUtils.showLong((CharSequence) getResources().getString(R.string.login_pwd_empty));
                } else if (password.length() < 6) {
                    ToastUtils.showLong((CharSequence) getResources().getString(R.string.login_pwd_six));
                } else if (!RegexUtils.isMatch(Constants.PWD_MATCHING, password)) {
                    ToastUtils.showLong((CharSequence) getResources().getString(R.string.mmgssryw));
                } else if (!NetworkUtils.isConnected()) {
                    ToastUtils.showLong((CharSequence) getString(R.string.no_net));
                } else {
                    CommSmallLoadingDialog.showDialog(this, getString(R.string.request_ing));
                    this.mIPresenter.load(phone_number, password, verificationCode);
                }
            }
        }
    }

    public void onClick(View view) {
        if (view.getId() == this.mImgBack.getId()) {
            finish();
        } else if (view.getId() == this.mImgPhoneNumberClean.getId()) {
            this.mEdtPhoneNumber.setText("");
        } else if (view.getId() == this.mTxtFinishAmend.getId()) {
            submit();
        }
    }

    public Context getContext() {
        return this;
    }

    public String getPhoneNumber() {
        return this.mEdtPhoneNumber.getText().toString();
    }

    /* access modifiers changed from: protected */
    public void onDestroy() {
        super.onDestroy();
        this.mIPresenter.destory();
    }
}